import 'package:flutter/material.dart';

import 'demos/img_demos.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: buildMainColumns(context),
          ),
        ),
      ),
    );
  }

  List<Widget> buildMainColumns(BuildContext context) {
    return <Widget>[
//      buildText(),
//      buildRichText(),
//      buildTextField(), //文本输入框
//      buildPasswordField(), //密码输入框
//      buildMaterialButton(),
//      buildFlatButton(),
//      buildRaisedButton(),
//      buildIconButton0(),
//      buildIconButton1(),
//      buildFloatingActionButton(),
//      buildDropdownButton(),
//      buildOutlineButton(context),
//      buildSwitch(),
//      buildCupertinoSwitch(),
//      buildSwitchListTile(),
//      buildRadio(),
//      buildRadioGroup(),
//      buildRadioListTile(),
//      buildCheckbox(),
//      buildCheckboxListTile(),
      buildImage(),
      buildNetworkImage(),
    ];
  }

  var radioValue = '默认值';

  Radio<String> buildRadio() {
    return new Radio(
      groupValue: this.radioValue,
      activeColor: Colors.blue,
      value: '用户选择值',
      onChanged: (String val) {
        this.setState(() {
          this.radioValue = val;
        });
      },
    );
  }

  Row buildRadioGroup() {
    return Row(
      children: <Widget>[
        Radio<String>(
            value: "单选框值1",
            groupValue: radioValue,
            onChanged: (val) {
              setState(() {
                radioValue = val;
              });
            }),
        Radio<String>(
            value: "单选框值2",
            groupValue: radioValue,
            onChanged: (val) {
              setState(() {
                radioValue = val;
              });
            }),
      ],
    );
  }

  var radioListValue = 0;

  Column buildRadioListTile() {
    return Column(
      children: <Widget>[
        RadioListTile(
          value: 0,
          groupValue: radioListValue,
          onChanged: (value) {
            setState(() {
              radioListValue = value;
            });
          },
          title: Text('单选框值1'),
          subtitle: Text('描述1'),
          secondary: Icon(Icons.filter_1),
          //右侧图标
          selected: radioListValue == 0,
        ),
        RadioListTile(
          value: 1,
          groupValue: radioListValue,
          onChanged: (value) {
            setState(() {
              radioListValue = value;
            });
          },
          title: Text('单选框值2'),
          subtitle: Text('描述2'),
          secondary: Icon(Icons.filter_2),
          //右侧图标
          selected: radioListValue == 0,
        ),
      ],
    );
  }

  var isChecked = true;

  Checkbox buildCheckbox() {
    return new Checkbox(
      value: this.isChecked,
      activeColor: Colors.blue,
      onChanged: (bool val) {
        setState(() {
          this.isChecked = val;
        });
      },
    );
  }

  CheckboxListTile buildCheckboxListTile() {
    return CheckboxListTile(
      secondary: const Icon(Icons.airplanemode_active),
      title: const Text('带标题复选框'),
      value: isChecked,
      onChanged: (bool value) {
        setState(() {
          isChecked = value;
        });
      },
    );
  }

  var isSwitchSelected = true;

  SwitchListTile buildSwitchListTile() {
    return new SwitchListTile(
      secondary: const Icon(Icons.airplanemode_active),
      title: const Text('带标题开关'),
      value: this.isSwitchSelected,
      onChanged: (bool value) {
        setState(() {
          this.isSwitchSelected = value;
        });
      },
    );
  }
}
